package com.lupan.effectiveJava.chapter2_initAndDestroyObject;

/**
 * 说明：
 *
 * @author lupan
 * @version 2016/5/27 13:31
 */
public class Student {

    //必须属性
    private final String name;
    private final String num;
    //可选属性
    private final Double height;
    private final Double weight;
    private final String hobby;
    private final String remark;

    public Student() {
        this.name = null;
        this.num = null;
        this.height = null;
        this.weight = null;
        this.hobby = null;
        this.remark = null;
    }

    /**
     * 静态工厂方法
     * @return
     */
    public static Student newInstance(){
        return new Student();
    }


    /**
     * 构建器来构建需要多参数初始化
     * @param builder
     */
    public Student(Builder builder) {
        this.name = builder.name;
        this.num = builder.num;
        this.height = builder.height;
        this.weight = builder.weight;
        this.hobby = builder.hobby;
        this.remark = builder.remark;
    }

    public static class Builder{
        //必须属性
        private final String name;
        private final String num;
        //可选属性
        private  Double height;
        private  Double weight;
        private  String hobby;
        private  String remark;

        public Builder(String name,String num){
            this.name = name;
            this.num = num;
        }

        public Builder height(Double height){
            this.height = height;
            return this;
        }
        public Builder weight(Double weight){
            this.weight = weight;
            return this;
        }
        public Builder hobby(String hobby){
            this.hobby = hobby;
            return this;
        }
        public Builder remark(String remark){
            this.remark = remark;
            return this;
        }

        public Student build(){
            return new Student(this);
        }
    }


}
